package com.market.cash.pro

import android.view.View
import com.market.cash.CashRootApps
import com.market.cash.base.BaseFragment
import com.market.cash.http.IHttpCallback
import com.market.cash.utils.event.CashRootEventData
import com.market.cash.utils.event.CashRootEventHelper
import com.market.cash.utils.event.CashRootSubscriber
import org.json.JSONObject

/**
 * CashRoot
 * @Author wwdeng
 * @CreateTime: 2024/10/16 10:32
 * @Annotation：
 */
abstract class ProFragment: BaseFragment(), CashRootSubscriber,IProView {

    override fun getAct(): ProActivity {
        return context as ProActivity
    }

    override fun onStart() {
        super.onStart()
        CashRootApps.app.publisher.register(this)
    }

    /**
     * 错误提示
     */
    fun showErrorTipsDialog(tips: String,eventRemark: String = ""){
        getAct().showErrorTipsDialog(tips,eventRemark)
    }

    /**
     * post
     */
    fun doPostAction(httpUrl: String, params: JSONObject, callback: IHttpCallback){
        getAct().doPostAction(httpUrl, params, callback)
    }

    /**
     * 牌照信息View
     */
    fun initCashRootLicenseView(): View {
        return getAct().initCashRootLicenseView()
    }

    /**
     * 添加埋点
     */
    fun addCashRootEventPoint(eventName: String, eventRemark: String = "") {
        CashRootEventHelper.addCashRootRequestEventAction(eventName,eventRemark)
    }

    /**
     * 发送事件通知
     */
    fun publishEventData(eventData: CashRootEventData){
        CashRootApps.app.publisher.publish(eventData)
    }

    /**
     * 处理订阅事件
     */
    override fun onCashRootEvent(event: CashRootEventData) {

    }

    override fun onDestroy() {
        super.onDestroy()
        CashRootApps.app.publisher.detach(this)
    }
}